<template>
	<uv-popup ref="popRef" bgColor="none">
		<view class="alert-layout">
			<view class="alert-box">
				<text class="alert-title">{{params.title}}</text>
					<view class="alert-subtitle-box">
						<slot>
							<text class="alert-subtitle">{{params.content}}</text>
						</slot>
					</view>
				<view class="alert-btn-box">
					<view class="btn alert-btn-cancel" @tap="close">{{params.cancelText}}</view>
					<view class="btn alert-btn-ok" @tap="submit">{{params.okText}}</view>
				</view>
			</view>
		</view>
	</uv-popup>
</template>

<script setup>
	import { ref } from 'vue'
	const popRef = ref(null)
	const params = ref({
		title:'温馨提示',
		cancelText:'取消',
		okText:'确认',
		content:''
	})
	const emits = defineEmits(['submit','cancel'])
	
	const open = (data)=>{
		params.value = {...params.value,...data}
		popRef.value.open()
	}
	const close = ()=>{
		emits('cancel',params.value)
		popRef.value.close()
	}
	// 确认
	const submit = ()=>{
		emits('submit',params.value)
		close()
	}
	defineExpose({
		open,
		close
	})
	
</script>

<style lang="scss" scoped>
	.alert-layout {
		width: 560rpx;
		.alert-box {
			display: flex;
			flex-direction: column;
			align-items: center;
			background-color: #fff;
			border-radius: 20rpx;
			padding: 40rpx;
			.alert-title{
				font-size: 32rpx;
				font-weight: bold;
			}
			.alert-subtitle-box{
				padding: 40rpx 0;
				text-align: center;
				font-size: 26rpx;
				color: $xh-color-9;
				line-height: 42rpx;
			}
			.alert-btn-box{
				display: flex;
				align-items: center;
			    justify-content: center;
				width: 100%;
				.btn{
					flex: 1;
					height: 72rpx;
					border-radius: 36rpx;
					font-size: 30rpx;
					line-height: 72rpx;
					text-align: center;
				}
				.alert-btn-ok{
					background-color: $xh-theme-color;
					color: #ffffff;
					margin-left: 40rpx;
				}
				.alert-btn-cancel{
					background-color: #ffffff;
					color: $xh-theme-color;
					border: 1px solid $xh-theme-color;
					
				}
			}
		}
	}
</style>